﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<Shape> shapes = new List<Shape>();

            Random rand = new Random();

            for (int i = 0; i < 10; i++)
            {
                int shapeType = rand.Next(3);

                if (shapeType == 0) // Rectangle
                {
                    double length = rand.NextDouble() * 10;
                    double width = rand.NextDouble() * 10;
                    shapes.Add(new Rectangle(length, width));
                }
                else if (shapeType == 1) // Square
                {
                    double side = rand.NextDouble() * 10;
                    shapes.Add(new Square(side));
                }
                else // Circle
                {
                    double radius = rand.NextDouble() * 10;
                    shapes.Add(new Circle(radius));
                }
            }

            double totalArea = 0;

            foreach (Shape shape in shapes)
            {
                if (shape.IsValid())
                {
                    totalArea += shape.CalculateArea();
                }
            }

            MessageBox.Show("结果为"+totalArea);
        }
    }
}
